package users;

import java.util.ArrayList;

/*
 * GroupTask class handles an individual group task dealing with the task data and all it's members.
 */
public class GroupTask {
	private int groupTaskID;
	private ArrayList<String> groupMembers = new ArrayList<String>();
	private TaskData task;
	
	public GroupTask(){
		groupTaskID = -1;
		task = new TaskData();
	}
	
	public GroupTask(int id, TaskData newTask) {
		groupTaskID = id;
		task = newTask;
		task.setTaskId(-1);
		task.setGroupID(groupTaskID);
	}
	
	public int getGroupTaskID() {
		return groupTaskID;
	}
	
	public final TaskData getTask() {
		return task;
	}
	
	public void setGroupTaskID(int id) {
		groupTaskID = id;
	}
	
	public void setTask(TaskData input) {
		task = input;
	}
	
	public void setMembers(String[] member) {
		groupMembers.clear();
		for(int x = 0; x < member.length; x++) {
			groupMembers.add(member[x]);
		}
	}
	
	public boolean addMember(String member) {
		if (groupMembers.contains(member)) {
			return false;
		}
		groupMembers.add(member);
		return true;
	}
	
	public boolean removeMember(String member) {
		if (!groupMembers.contains(member)) {
			return false;
		}
		groupMembers.remove(groupMembers.indexOf(member));
		return true;
	}
	
	public boolean isMember(String name) {
		if(groupMembers.contains(name)) {
			return true;
		}
		return false;
	}
	
	public boolean noMembers() {
		return groupMembers.isEmpty();
	}
	
	public void editTask(TaskData editedTask) {
		task = editedTask;
	}
	
	public String getMembersToString() {
		String returnMembers = "";
		for(int x = 0; x < groupMembers.size(); x++) {
			returnMembers += groupMembers.get(x) + "\n";
		}
		return returnMembers;
	}
	
	public String getMembersToStringOneLine() {
		String returnMembers = "";
		for(int x = 0; x < groupMembers.size(); x++) {
			returnMembers += groupMembers.get(x);
			if(x != (groupMembers.size()-1)) {
				returnMembers += ", ";
			}
		}
		return returnMembers;
	}
}
